#include "TeamsManagementMenu.h"
#include "Utilities.h"
#include "PrintUtilities.h"
#include "EditFormationMenu.h"
#include "MarketMenu.h"
#include "UserManager.h"
#include "Team.h"
#include "ServiceProvider.h"
#include "MenuManager.h"

TeamsManagementMenu::TeamsManagementMenu(MenuManager* const i_menuManager)
	: Menu(i_menuManager)
{
}

void TeamsManagementMenu::Draw() const
{
	std::cout << Print::Title("TEAM MANAGEMENT MENU'");

	const UsersList& users = GetSP()->GetUserMgr().GetUserList();

	for (int i = 0; i < static_cast<int>(users.size()); ++i)
		std::cout	<< i+1 << ") user: " << users.at(i)->m_name
					<< "  -  " << users.at(i)->m_team->GetName()
					<< std::endl;
	if (users.empty())
	{
		std::cout	<< " No user teams available to edit!\n\n"
					<< Print::Options("0) Return to previous menu'");
	}
	else
	{
		std::cout	<< "\n"
					<< Print::Options(	"num) Team to manage.\n\n"
										"0)   Return to previous menu'");
	}
	std::cout << "Selection: ";
}


bool TeamsManagementMenu::Input(const std::string& i_input)
{
	bool goodInput = true;

	int res = Utilities::StringToInt(i_input);

	if (res < 0 || res > static_cast<int>(GetSP()->GetUserMgr().GetUserList().size()))
		return false;

	if (res == 0)
	{
		GetMM()->SetMenu(GetMM()->GetMainMenu());
	}
	else
	{
		EditFormationMenu* editFormation = static_cast<EditFormationMenu*>(GetMM()->GetEditFormationMenu());
		editFormation->m_userIndex = res - 1;

		MarketMenu* market = static_cast<MarketMenu*>(GetMM()->GetMarketMenu());
		market->m_userIndex = res - 1;

		GetMM()->SetMenu(editFormation);
	}


	return goodInput;
}